﻿package mortal.game.view.lotteryDraw
{
    import baseEngine.basic.*;
    import baseEngine.modifiers.*;
    import com.gengine.global.*;
    import com.gengine.resource.*;
    import com.gengine.resource.info.*;
    import com.mui.controls.*;
    import com.mui.core.*;
    import flash.display.*;
    import flash.events.*;
    import flash.utils.*;
    import frEngine.primitives.object2d.*;
    import frEngine.render.layer.*;
    import frEngine.render.layer.uiEffectLayer.*;
    import mortal.component.window.*;
    import mortal.game.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.scene3D.map3D.*;
    import mortal.game.scene3D.model.player.*;
    import mortal.game.scene3D.model.pools.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.display.*;
    import mortal.game.view.task.data.*;
    import mortal.mvc.core.*;

    public class lotteryDrawDiamondWin extends Window
    {
        private var _bg3d:Img2D;
        private var _item3d:Img2D;
        private var _getBtn:GLoadingButton;
        private var _bmpTxt:BitmapNumberText;
        private var _activeZuanView:LotteryDrawActiveZuanView;
        private var _lSpotlightPlayer:EffectPlayer;
        private var _rSpotlightPlayer:EffectPlayer;
        private var _lFireworksPlayer:EffectPlayer;
        private var _rFireworksPlayer:EffectPlayer;
        private var _t:uint;
        private var _bd:BitmapData;
        private var _flyData:Object;
        private static var _instance:lotteryDrawDiamondWin;
        private static const is3dBg:Boolean = false;

        public function lotteryDrawDiamondWin()
        {
            this.layer = LayerManager.topLayer;
            return;
        }// end function

        public function set data(param1:Object) : void
        {
            if (!this.isDisposed && this._bmpTxt)
            {
                this._bmpTxt.text = String(param1.num);
            }
            if (param1.num < 0)
            {
                if (this._activeZuanView == null)
                {
                    this._activeZuanView = UIFactory.getUICompoment(LotteryDrawActiveZuanView, 230, 130, this);
                    if (this._activeZuanView.isDisposed)
                    {
                        this._activeZuanView.createDisposedChildren();
                    }
                }
                this._activeZuanView.updateNum(Math.abs(param1.num));
                this._bmpTxt.visible = false;
            }
            else
            {
                this._bmpTxt.visible = true;
                if (this._activeZuanView != null)
                {
                    this._activeZuanView.dispose();
                    this._activeZuanView = null;
                }
            }
            this._flyData = {rewards:param1.rewards, startPos:param1.startPos};
            return;
        }// end function

        private function add2d() : void
        {
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.zhongjiangbg, -354 + 307, -132 + 57, this));
            this.pushUIToDisposeVec(UIFactory.gBitmap(ImagesConst.zuanshi, 201 - 55, 106 - 13, this));
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this.setSize(600, 200);
            if (!is3dBg)
            {
                this.add2d();
            }
            this._getBtn = UIFactory.gLoadingButton(ResFileConst.ZhongJiangBtn, 173 + 65 - 55, 160 + 52 - 25, 125, 44, this);
            this._getBtn.configEventListener(MouseEvent.CLICK, this.onClickHandle);
            this._bmpTxt = UIFactory.bitmapNumberText(300 - 55 + 39, 27 + 213 - 111, "PetGrowYellowNum.png", 18, 21, -2, this, 9, BitmapNumberText.Mid);
            this._bmpTxt.text = "0";
            var _loc_1:* = ImagesConst.zhongjiangbg + ".swf";
            if (!this._bd)
            {
                LoaderManager.instance.load(_loc_1, this.onLoadCompl, 3, null, null, null);
            }
            else
            {
                this.createChildren();
            }
            return;
        }// end function

        private function onLoadCompl(param1:SWFInfo) : void
        {
            this._bd = param1.bitmapData;
            this.createChildren();
            return;
        }// end function

        private function createChildren() : void
        {
            if (is3dBg)
            {
                this.add3d();
            }
            this.playAllEffect();
            return;
        }// end function

        private function onClickHandle(event:MouseEvent) : void
        {
            this.hide();
            return;
        }// end function

        private function remove3d() : void
        {
            if (this._lSpotlightPlayer)
            {
                this._lSpotlightPlayer.dispose();
                this._lSpotlightPlayer = null;
            }
            if (this._rSpotlightPlayer)
            {
                this._rSpotlightPlayer.dispose();
                this._rSpotlightPlayer = null;
            }
            if (this._lFireworksPlayer)
            {
                this._lFireworksPlayer.dispose();
                this._lFireworksPlayer = null;
            }
            if (this._rFireworksPlayer)
            {
                this._rFireworksPlayer.dispose();
                this._rFireworksPlayer = null;
            }
            return;
        }// end function

        private function add3d() : void
        {
            var _loc_2:BitmapData = null;
            var _loc_1:* = UIEffectList.instance.getRenderListByUILayerID(UILayerIDs.ScreenID);
            if (!this._bg3d)
            {
                this._bg3d = new Img2D("bg3d", this._bd, this._bd.rect, true);
                this._bg3d.setLayer(Layer3DManager.backGroudImgLayer);
                this._bg3d.renderList = _loc_1;
            }
            if (!this._item3d)
            {
                _loc_2 = GlobalClass.getBitmapData(ImagesConst.zuanshi);
                this._item3d = new Img2D("item3d", _loc_2, _loc_2.rect, true);
                this._item3d.setLayer(Layer3DManager.backGroudImgLayer);
                this._item3d.renderList = _loc_1;
            }
            Game.scene.playerLayer.addChild(this._bg3d);
            Game.scene.playerLayer.addChild(this._item3d);
            return;
        }// end function

        override public function stageResize() : void
        {
            super.stageResize();
            var _loc_1:* = SceneRange.display.width;
            var _loc_2:* = SceneRange.display.height;
            if (this._lSpotlightPlayer)
            {
                this._lSpotlightPlayer.x = -0.5 * _loc_1;
                this._lSpotlightPlayer.y = 0.5 * _loc_2;
            }
            if (this._rSpotlightPlayer)
            {
                this._rSpotlightPlayer.x = 0.5 * _loc_1;
                this._rSpotlightPlayer.y = 0.5 * _loc_2;
            }
            if (this._lFireworksPlayer)
            {
                this._lFireworksPlayer.x = -0.5 * _loc_1;
            }
            if (this._rFireworksPlayer)
            {
                this._rFireworksPlayer.x = 0.5 * _loc_1;
            }
            if (this._bg3d)
            {
                this._bg3d.x = (_loc_1 - this._bd.width) / 2;
                this._bg3d.y = (_loc_2 - this._bd.height) / 2;
            }
            if (this._item3d)
            {
                this._item3d.x = this._bg3d.x + 200 + 48;
                this._item3d.y = this._bg3d.y + 200 - 15;
            }
            return;
        }// end function

        override public function hide() : void
        {
            super.hide();
            var _loc_1:* = CopyUtil.isInCopy;
            if (!_loc_1)
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.TaskShowHideTrackExceptBtn, true));
            }
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this.remove3d();
            if (this._item3d)
            {
                this._item3d.dispose();
                this._item3d = null;
            }
            if (this._bg3d)
            {
                this._bg3d.dispose();
                this._bg3d = null;
            }
            this._bmpTxt.dispose(param1);
            this._bmpTxt = null;
            this._getBtn.dispose(param1);
            this._getBtn = null;
            this.clearTimer();
            if (this._activeZuanView != null)
            {
                this._activeZuanView.dispose(param1);
                this._activeZuanView = null;
            }
            super.disposeImpl(param1);
            return;
        }// end function

        private function playAllEffect() : void
        {
            if (this._lSpotlightPlayer)
            {
                this._lSpotlightPlayer.dispose();
            }
            if (this._rSpotlightPlayer)
            {
                this._rSpotlightPlayer.dispose();
            }
            if (this._lFireworksPlayer)
            {
                this._lFireworksPlayer.dispose();
            }
            if (this._rFireworksPlayer)
            {
                this._rFireworksPlayer.dispose();
            }
            var _loc_1:* = UIEffectList.instance.getRenderListByUILayerID(UILayerIDs.ScreenID);
            this._lSpotlightPlayer = EffectPlayerPool.instance.getEffectPlayer("choujiang_02", Game.scene.playerLayer, _loc_1, false);
            this._lSpotlightPlayer.play(PlayMode.ANIMATION_LOOP_MODE);
            this._rSpotlightPlayer = EffectPlayerPool.instance.getEffectPlayer("choujiang_03", Game.scene.playerLayer, _loc_1, false);
            this._rSpotlightPlayer.play(PlayMode.ANIMATION_LOOP_MODE);
            this._lFireworksPlayer = EffectPlayerPool.instance.getEffectPlayer("choujiang_01", Game.scene.playerLayer, _loc_1, false);
            this._lFireworksPlayer.play(PlayMode.ANIMATION_LOOP_MODE);
            this._rFireworksPlayer = EffectPlayerPool.instance.getEffectPlayer("choujiang_01", Game.scene.playerLayer, _loc_1, false);
            this._rFireworksPlayer.play(PlayMode.ANIMATION_LOOP_MODE);
            this.stageResize();
            this.addTimer();
            return;
        }// end function

        private function addTimer() : void
        {
            this.clearTimer();
            this._t = setTimeout(this.onTimeEnd, 6000);
            return;
        }// end function

        private function onTimeEnd() : void
        {
            this.clearTimer();
            this.remove3d();
            return;
        }// end function

        private function clearTimer() : void
        {
            if (this._t)
            {
                clearTimeout(this._t);
                this._t = 0;
            }
            return;
        }// end function

        private function hideUI() : void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.TaskShowHideTrackExceptBtn, false));
            return;
        }// end function

        override public function show(param1:int = 0, param2:int = 0) : void
        {
            if (this.isHide)
            {
                super.show();
                this.hideUI();
            }
            else
            {
                this.playAllEffect();
                this.addTimer();
            }
            this.x = Global.stage.stageWidth - this.width >> 1;
            this.y = Global.stage.stageHeight - this.height >> 1;
            return;
        }// end function

        public static function get instance() : lotteryDrawDiamondWin
        {
            if (!_instance)
            {
                _instance = new lotteryDrawDiamondWin;
            }
            return _instance;
        }// end function

    }
}
